package com.example.springboot.controller;

import com.example.springboot.common.request.AddBookRequest;
import com.example.springboot.common.request.BorrowListRequest;
import com.example.springboot.common.result.Result;
import com.example.springboot.entity.Borrow;
import com.example.springboot.entity.Category;
import com.example.springboot.service.BorrowService;
import com.example.springboot.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/borrow")
public class BorrowController {

    @Autowired
    private BorrowService borrowService;
    
    /**
     * 根据书名模糊查询
     * @param borrowListRequest
     * @return
     */
    @GetMapping("/page")
    public Result page(BorrowListRequest borrowListRequest) {
        return Result.success(borrowService.page(borrowListRequest));
    }

    /**
     * 添加图书借阅
     * @param borrow
     * @return
     * @throws Exception
     */
    @PostMapping("/save")
    public Result save(@RequestBody Borrow borrow) throws Exception {
        borrowService.save(borrow);
        return Result.success();
    }

    /**
     * 根据id获取需要修改的图书信息
     * @param id
     * @return
     */
    @GetMapping("/update/{id}")
    public Result getById(@PathVariable Integer id) {
        Borrow borrow = borrowService.getById(id);
        return Result.success(borrow);
    }

    /**
     * 更新图书信息
     * @param borrow
     * @return
     * @throws Exception
     */
    @PutMapping("/update")
    public Result editUser(@RequestBody Borrow borrow) throws Exception {
        borrowService.update(borrow);
        return Result.success();
    }

    /**
     * 根据id删除图书分类
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        borrowService.deleteById(id);
        return Result.success();
    }



}
